<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        /*
        1.菜场买菜
        2.回家洗菜
        3.开始做饭
        4.做饭完成开始吃饭
        5.吃完饭洗碗
         */
        let flag = 1;
        function step1(resolve,reject){
            console.log('准备去买菜');
            if(flag){
                resolve('我女朋友不挑食,什么都吃')
            }else {
                reject('街上没有菜')
            }
        }

        function step2(resolve,reject){
            console.log('准备洗菜');
            if(flag ==1){
                resolve('洗菜顺利')
            }else{
                reject('家里没水')
                flag = 0;
            }
        }

        function step3(resolve,reject){
            console.log('开始做饭');
            if(flag ==1){
                resolve('做饭已经完成')
            }else{
                reject('家里没有煤气')
            }
        }

        function step4(resolve,reject){
            console.log('开始吃饭');
            if(flag ==1){
                resolve('吃饭已经完成')
            }else{
                reject('饭没法吃')
            }
        }

        new Promise(step1).then((val1)=>{
            console.log(val1);
            return new Promise(step2)
        }).then((val2) => {
            console.log(val2);
            return new Promise(step3)
        }).then((val3) => {
            console.log(val3);
            return new Promise(step4)
        }).then((val4) => {
            console.log(val4);
        })
        
    </script>
</body>
</html>